<template>
  <div id="app">
    <h2>测试题</h2>
    <subject :arr="list" @btnType="allbtn"></subject>
    <div>
      <flag :arr="list"></flag>
    </div>
  </div>
</template>

<script>
import subject from "./components/two-timu";
import flag from "./components/two-jieguo";
export default {
  components: {
    subject,
    flag,
  },
  data() {
    return {
      list: [
        {
          id: 1,
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          jin: "",
          color: "",
        },
        {
          id: 2,
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          jin: "",
          color: "",
        },
        {
          id: 3,
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          jin: "",
          color: "",
        },
        {
          id: 4,
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          jin: "",
          color: "",
        },
      ],
    };
  },
  methods: {
    allbtn(item) {
      console.log(item);
      item.jin = true;

      if (Number(item.num1 + item.num2) == item.sumadd) {
        item.status = "正确";
        item.color = true;
      } else if (Number(item.num1 + item.num2) !== item.sumadd) {
        item.status = "错误";
        item.color = false;
      } else {
        item.status = "未完成";
      }
    },
  },
  computed: {},
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>